<template>
    <div style="height:100%;">
        <navbar class="header-title-01 header-title-00 header-white">
            <template #left>
                <span class="iconfont icon-left head-left" @click="backToFind"></span>
            </template>
            <template #title >
                <van-tabs type="card" class="tab-button-01" @click="jump" v-model="active">
                    <!-- 我的问题 -->
                    <van-tab :title="$t('know_my_question')"></van-tab>
                    <!-- 我的回答 -->
                    <van-tab :title="$t('know_my_answer')"></van-tab>
                </van-tabs>
            </template>
        </navbar>
        <div class="content">
            <!-- <keep-alive> -->
                <router-view></router-view>
            <!-- </keep-alive> -->
        </div>
        <router-link tag="div" class="add-icon-box" to="/addQuestion">
            <i class="add-icon"></i>
        </router-link>
    </div>
</template>

<script>
import bottomNav from '@/components/know/BottomNav.vue';
export default {
    name: 'RelatedToMe',
    components: {
    },
    BottomNav: [bottomNav],
    data() {
        return {
            path: '',
            encIdWb: '',
            active: 0
        };
    },
    methods: {
        jump(index) {
            switch (index) {
            case 0:
                this.$router.replace({path: 'myQuestion'});
                break;
            case 1:
                this.$router.replace({path: 'myAnswer'});
                break;
            }
        },
        backToFind() {
            if (window.localStorage.getItem('loginUser')) {
                this.encIdWb = this.wbEncryptor(window.localStorage.getItem('loginUser'));
            } else {
                this.$axios({
                    method: 'GET',
                    url: '/app/api/user/current'
                }).then(res => {
                    this.encIdWb = this.wbEncryptor(res.data.usrEntId);
                });
            }
            this.$store.commit('removeKeepAliveList', 'KnowIndex');
            if (window.localStorage.getItem('formUrl') === '1') {
                window.localStorage.removeItem('formUrl');
                this.$router.push(`/`);
            } else {
                window.localStorage.removeItem('formUrl');
                this.$router.replace(`/find/${this.encIdWb}`);
            }
        }
    },
    activated() {
        this.path = this.$route.path;
        this.active = this.path.indexOf('myQuestion') !== -1 ? 0 : 1;
    }
};
</script>

<style scoped lang="less">
    /deep/.van-tabs__nav--card{
        border: 1px solid #075ebb;
        border-radius: 18px;
        .van-tab{
            color: #075ebb;
            border-right: none;
        }
        .van-tab.van-tab--active{
            background-color: #075ebb;
        }
        .van-tab:nth-child(1){
            border-top-left-radius: 18px;
            border-bottom-left-radius: 18px;
        }
        .van-tab:nth-child(2){
            border-top-right-radius: 18px;
            border-bottom-right-radius: 18px;
        }
        .van-tab.van-tab--active {
            color: white;
        }
    }
    /deep/.van-nav-bar__content .van-nav-bar__title {
        max-width: 80%;
        width: 80%;
        margin-left: 50px;
    }
    .header-white {
        background-color: #fff;
    }
</style>
